﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dominion.Core;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Reflection;

namespace Dominion.Core.Factories
{
    public static class CardFactory
    {


        public static Card CreateCopper() { return new Treasure { Kind = Kind.Copper, Price = 0, Value = 1 }; }
        public static Card CreateSilver() { return new Treasure { Kind = Kind.Silver, Price = 3, Value = 2 }; }
        public static Card CreateGold() { return new Treasure { Kind = Kind.Gold, Price = 6, Value = 3 }; }

        public static Card CreateMalediction() { return new Malediction { Kind = Kind.Malediction, Price = 0, MaledictionPoints = -1 }; }

        public static Card CreateEstate() { return new Victory { Kind = Kind.Estate, Price = 2, VictoryPoints = 2 }; }
        public static Card CreateDuchy() { return new Victory { Kind = Kind.Duchy, Price = 5, VictoryPoints = 3 }; }
        public static Card CreateProvince() { return new Victory { Kind = Kind.Province, Price = 8, VictoryPoints = 6 }; }



        private static IDictionary<Kind, Func<Kind, Card>> kingdomCreators = new Dictionary<Kind, Func<Kind, Card>> { 
            {Kind.Cellar, CreateCellar},
            {Kind.Chapel, CreateChapel},
            {Kind.Moat, CreateMoat},

            {Kind.Chancellor, CreateChancellor},
            {Kind.Village, CreateVillage},
            {Kind.Woodcutter, CreateWoodcutter},
            {Kind.Workshop, CreateWorkshop},

            {Kind.Bureaucrat, CreateBureaucrat},
            {Kind.Feast, CreateFeast},
            {Kind.Gardens, CreateGardens},
            {Kind.Milicia, CreateMilicia},
            {Kind.MoneyLender, CreateMoneylender},
            {Kind.Remodel, CreateRemodel},
            {Kind.Smithy, CreateSmithy},
            {Kind.Spy, CreateSpy},
            {Kind.Thief, CreateThief},
            {Kind.Throneroom, CreateThroneroom},

            {Kind.Councilroom, CreateCouncilroom},
            {Kind.Festival, CreateFestival},
            {Kind.Laboratory, CreateLaboratory},
            {Kind.Library, CreateLibrary},
            {Kind.Market, CreateMarket},
            {Kind.Mine, CreateMine},
            {Kind.Witch, CreateWitch},
          
            {Kind.Adventurer, CreateAdventurer}
        };


        public static IEnumerable<Card> CreateKingdom(Kind kind, int nb)
        {
            for (int i = 0; i < nb; i++)
                yield return CreateKingdom(kind);
        }

        public static Card CreateKingdom(Kind kind)
        {
            if (kingdomCreators.Keys.Contains(kind))
            {
                Card card = kingdomCreators[kind].Invoke(kind);
                return card;
            }
            else
            {
                return null;
            }
        }

        // 2
        private static Card CreateCellar(Kind kind) { return new Kingdom { Kind = kind, Price = 2, Behavior = new CellarBehavior() }; }
        private static Card CreateChapel(Kind kind) { return new Kingdom { Kind = kind, Price = 2, Behavior = new ChapelBehavior() }; }
        private static Card CreateMoat(Kind kind) { return new Kingdom { Kind = kind, Price = 2, Behavior = new MoatBehavior() }; }
        // 3
        private static Card CreateChancellor(Kind kind) { return new Kingdom { Kind = kind, Price = 3, Behavior = new ChancellorBehavior() }; }
        private static Card CreateVillage(Kind kind) { return new Kingdom { Kind = kind, Price = 3, Behavior = new VillageBehavior() }; }
        private static Card CreateWoodcutter(Kind kind) { return new Kingdom { Kind = kind, Price = 3, Behavior = new WoodcuttereBehavior() }; }
        private static Card CreateWorkshop(Kind kind) { return new Kingdom { Kind = kind, Price = 3, Behavior = new NullBehavior() }; }
        // 4
        private static Card CreateBureaucrat(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new NullBehavior() }; }
        private static Card CreateFeast(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new NullBehavior() }; }
        private static Card CreateGardens(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new NullBehavior() }; }
        private static Card CreateMilicia(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new MiliciaBehavior() }; }
        private static Card CreateMoneylender(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new MoneyLenderBehavior() }; }
        private static Card CreateRemodel(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new NullBehavior() }; }
        private static Card CreateSmithy(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new SmithyBehavior() }; }
        private static Card CreateSpy(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new SpyBehavior() }; }
        private static Card CreateThief(Kind kind) { return new Kingdom { Kind = kind, Price = 4, Behavior = new ThiefBehavior() }; }
        private static Card CreateThroneroom(Kind kind) { return new Kingdom { Kind = kind, Price = 4 }; }
        // 5
        private static Card CreateCouncilroom(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new CouncilroomBehavior() }; }
        private static Card CreateFestival(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new FestivalBehavior() }; }
        private static Card CreateLaboratory(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new LaboraoryBehavior() }; }
        private static Card CreateLibrary(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new NullBehavior() }; }
        private static Card CreateMarket(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new MarketBehavior() }; }
        private static Card CreateMine(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new MarketBehavior() }; }
        private static Card CreateWitch(Kind kind) { return new Kingdom { Kind = kind, Price = 5, Behavior = new NullBehavior() }; }
        // 6
        private static Card CreateAdventurer(Kind kind) { return new Kingdom { Kind = kind, Price = 5 }; }

    }
}

